home *** CD-ROM | disk | FTP | other *** search
/ BMUG Revelations / BMUG Revelations.toast / Utilities / Network / QUE / Basic / queread.c < prev    next >
C/C++ Source or Header  |  1989-08-03  |  3KB  |  127 lines

  1. /*
  2. ------------------------------------------------------------
  3. Copyright © 1989 Rob Kassel, Mike McCandless and the Massachusetts Institute of Technology
  4.  
  5. Permission to use, copy, modify, and distribute this software and its documentation for any purpose without fee is hereby granted, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation, and that the name of M.I.T. not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission.  The authors and M.I.T. make no representations about the suitability of this software for any purpose.  It is provided “as is” without express or implied warranty.
  6. ------------------------------------------------------------
  7. */
  8.  
  9. #include "mail.h"
  10.  
  11.  
  12. main() {
  13. int fd;
  14. int nxtMsg,nxtRdMsg;
  15. int errno;
  16. char *sys_errlist[],*fName;
  17.  
  18.  
  19. fd = fileThere(TOREAD);
  20.  
  21. if (fd == 1)
  22.     fileLoad((char*) 0,0);
  23.  
  24. else  {
  25.     fName = getNextFile();
  26.     if (fName == NULL){
  27.         printf("No mail to read.\n");
  28.         exit(0);
  29.           }
  30.     else
  31.         fileLoad(fName,1);
  32. }
  33. }
  34.  
  35.  
  36. fileLoad(nme,flg)
  37.  
  38. char *nme;
  39. int flg;
  40.  
  41. {
  42. FILE *fopen(),*fpIn;
  43. char *fName,*pLine;
  44.  
  45. pLine = alcCh(MAXLINE);
  46.  
  47. if (flg)
  48.     if (rename(nme,TOREAD) != 0) {
  49.         printf("Couldn't rename next mail file.\n");
  50.         printf("%s\n",sys_errlist[errno]);
  51.         exit(1);
  52.     }
  53.  
  54. fpIn = fopen(TOREAD,"r");
  55. if (fpIn == NULL) {
  56.     printf("Couldn't open mail file %s for input.\n",TOREAD);
  57.     exit(1);
  58. }
  59.  
  60. printf("Message in 5\n");
  61. sleep(5);
  62. while (fgets(pLine,MAXLINE,fpIn) != NULL)
  63.     putline(pLine);
  64. printf("ENDOFMESSAGETOMACQRLMT\nFrom m\n");
  65. fclose(fpIn);
  66. }
  67.  
  68.  
  69.  
  70. putline(s)
  71.  
  72. char s[];
  73. {
  74.     int n,i;
  75.     char *cs;
  76.  
  77.     n = strlen(s);
  78.     i = 0;
  79.     while (i < n) {
  80.         putchar(s[i]);
  81.         i++;
  82.     }
  83. }
  84.  
  85.  
  86. char* getNextFile() {
  87.  
  88. struct dirent* myEntry;
  89. DIR *dp,*opendir();
  90. int lp,done,errr,lnn;
  91. char *toReturn;
  92.  
  93. dp = opendir(".");
  94. if (dp == NULL) {
  95.         printf("Couldn't open directory.\n\n");
  96.         exit(1);
  97. }
  98.  
  99. myEntry = readdir(dp);
  100. done = FALSE;
  101. errr = FALSE;
  102.  
  103. while (!done) {
  104.         myEntry = readdir(dp);
  105.         if (myEntry == NULL) {
  106.                 errr = TRUE;
  107.                 done = TRUE;
  108.                 break;
  109.         }
  110.         if ((char)*(myEntry->d_name) != '.') {
  111.         lnn = strlen(MSGHDR);
  112.         if(!strncmp(myEntry->d_name,MSGHDR,lnn))
  113.         if(strcmp(myEntry->d_name,TOREAD) != 0)
  114.              done = TRUE;
  115.     }
  116. }
  117.  
  118. if (errr)
  119.     return(NULL);
  120.  
  121. else {
  122.     toReturn = alcCh(MAXLINE); 
  123.     strcpy(toReturn,myEntry->d_name);
  124.     return(toReturn);
  125. }
  126. }
  127.